package com.appcenter.application.mapper;

import com.appcenter.application.dto.externalapi.BusinessSystemOrgDto;
import com.appcenter.application.dto.orgs.OrgDto;
import com.appcenter.application.dto.orgusers.ResultOrgUserDto;
import com.appcenter.application.input.orguser.GetOrgUsersInput;
import com.appcenter.application.model.OrgUsers;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

@org.apache.ibatis.annotations.Mapper
@Repository
public interface OrgUsersMapper extends Mapper<OrgUsers> {

    @Delete("delete from orgusers where UserId=#{UserId}")
    public int deleteOrgUserByUserId(String UserId);

    @SelectProvider(type=OrgUsersProvider.class,method="searchOrgUsers")
    public List<ResultOrgUserDto> searchOrgUsers(GetOrgUsersInput input);


    @Select("select b.* from orgusers a inner join orgs b " +
            " on a.orgid=b.id " +
            " where a.userid= #{userId} " +
            " and a.VersionNo= #{versionNo} " +
            " and b.VersionNo= #{versionNo} ")
    public List<OrgDto> getOrgsByUserId(Map<String,Object> param);



    @Select("select b.* from orgusers a inner join orgs b " +
            " on a.orgid=b.id " +
            " where a.userid= #{userId} " +
            " and a.VersionNo= #{versionNo} " +
            " and b.VersionNo= #{versionNo} ")
    public List<BusinessSystemOrgDto> getBusinessSystemOrg(Map<String,Object> param);


}
